<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	$basic=$this->plugin_setting('basic');
	$return['welcomehdps']=$basic['welcomehdps'];
	if(count($return['welcomehdps'])>0 && $basic['iswelcome']==1){
		$return['iswelcome']=$this->session('iswelcome')?0:1;
		if($return['iswelcome']){
			$this->session('iswelcome',1);
		}
	}
	$return['list']=array();
	$return['notices']=pdo_getall('core_account_article',array('uniacid'=>$_SESSION['uniacid']));
	set_html('title',$basic['title']?$basic['title']:'轻松点餐');
	$return['sharedata']=array(
		'title'=>$basic['share_title'],
		'desc'=>$basic['share_desc'],
		'link'=>custom_url('jy_dish/index/',true),
		'imgUrl'=>ATTACHMENT_URL.$basic['share_image'],
	);
	exi($return);
}
if($_RQ['op']=='list'){
	$post=get_postdata();
	$params=array('uniacid'=>$_SESSION['uniacid']);
	$pindex = max(1, intval($post['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_dish_store',$params,array($pindex,$psize),$total,$fields,'','display desc');
	if(empty($list)){
		$list = array(
			array('title'=>'莲庄客府')
		);
	}
	if($post['lat_lng']){
		foreach($list as &$v){
			$v['lat_lng']=json_decode($v['lat_lng'],true);
			if($v['lat_lng']){				
				$v['distance']=cfc('tools')->getdistance($post['lat_lng']['lng'],$post['lat_lng']['lat'],$v['lat_lng']['lng'],$v['lat_lng']['lat']);
				$v['distance']=intval($v['distance']/1000);
			}
			$v['ordernum']=pdo_count('jy_dish_order',array('uniacid'=>$_SESSION['uniacid'],'store_id >'=>$v['id']));
		}
		paixu($list,'distance');
	}else{
		foreach($list as &$v){
			$v['ordernum']=pdo_count('jy_dish_order',array('uniacid'=>$_SESSION['uniacid'],'store_id >'=>$v['id']));
		}
	}
	$return['list']=$list;
	exi($return);
}	
?>